package com.an.blog.web.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.collection.CollectionUtil;
import com.an.blog.admin.domain.vo.BlogDailyImageVo;
import com.an.blog.third.job.BlogJobService;
import com.an.common.constant.CacheConstants;
import com.an.common.core.domain.R;
import com.an.common.utils.redis.RedisUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 博客每日图片网页控制器
 *
 * @author: Ann
 * @createDate: 2023/09/25 14:08:04
 * @version: 1.0.0
 */
@SaIgnore
@RequiredArgsConstructor
@RestController
@RequestMapping("/blog-web/dailyImage")
public class BlogDailyImageWebController {

    private final BlogJobService blogJobService;


    /**
     * 查询每日图片列表
     *
     * @return {@link R }<{@link List }<{@link BlogDailyImageVo }>>
     * @author: Ann
     * @createDate: 2023/09/25 14:09:14
     * @version: 1.0.0
     */
    @GetMapping("/list")
    public R<List<BlogDailyImageVo>> queryDailyImageList() {
        List<BlogDailyImageVo> dailyImageVos = RedisUtils.getCacheList(CacheConstants.BLOG_DAILY_IMAGE);
        if(CollectionUtil.isEmpty(dailyImageVos)){
            dailyImageVos = blogJobService.refreshImageCacheHandler();
        }
        return R.ok(dailyImageVos);
    }

}
